﻿using Castle.DynamicProxy;
using CNKI.TPI.Web.Base;
using CNKI.TPI.Web.Interface.Models;
using CNKI.TPI.Web.Search.IBLL;
using CNKI.TPI.Web.Search.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;

namespace CNKI.TPI.Web.Interface.Areas.Category.Controllers
{
    public class UpdateCategoryTypeController : BaseApiController
    {
        INaviService naviService = null;
        public UpdateCategoryTypeController(INaviService naviService)
        {
            this.naviService = generator.CreateInterfaceProxyWithTarget<INaviService>(naviService, new IInterceptor[] { new LogInterceptor() });
        }

        // POST api/updatecategory
        [ValidateInput(false)]
        public object Post()
        {
            OutputEntity result = new OutputEntity();
            try
            {
                HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];//获取传统context     
                HttpRequestBase request = context.Request;//定义传统request对象
                string dbcode = request.Form["dbcode"];
                string data = request.Form["data"];
                string sysid = request.Form["sysid"];

                if (!string.IsNullOrEmpty(data))
                {
                    Dictionary<string, object> content = SerializeHelper.Deserialize<Dictionary<string, object>>(data);
                    bool status = naviService.UpdateCategoryType(dbcode, sysid, content);
                    if (status)
                    {
                        result.Status = Status.Success;
                    }
                    else
                    {
                        result.Status = Status.Error;
                    }
                }
                else
                {
                    result.Status = Status.Error;
                }
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
                result.Status = Status.Error;
                result.message = ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 获取分类导航数据
        /// </summary>
        /// <param name="dbCode">数据库编码Code</param>
        /// <param name="dbID">数据库ID</param>
        /// <returns></returns>
        //public object UpdateCategoryType(string dbCode, string sysid, string data)
        //{
        //    OutputEntity result = new OutputEntity();
        //    try
        //    {
        //        if (!string.IsNullOrEmpty(data))
        //        {
        //            Hashtable content = SerializeHelper.Deserialize<Hashtable>(data);
        //            bool status = naviService.UpdateCategoryType(dbCode, sysid, content);
        //            if (status)
        //            {
        //                result.Status = Status.Success;
        //            }
        //            else
        //            {
        //                result.Status = Status.Error;
        //            }
        //        }
        //        else
        //        {
        //            result.Status = Status.Error;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        LogOpr.Error(ex.ToString());
        //        result.Status = Status.Error;
        //    }
        //    return result;
        //}

        
    }
}
